package com.spvs.approval.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;


/**
 * Map工具类
 *
 */
public class MapUtils extends HashMap<String, Object> {

    @Override
    public MapUtils put(String key, Object value) {
        super.put(key, value);
        return this;
    }


    public static Map<String, Object> StringToMap(String param) {
        Map<String, Object> map = new HashMap<>();
        //去除{}
        String s1 = param.replace("{", "");
        String s2 = s1.replace("}", "");
        String s3 = s2.trim();
        if(StringUtils.isNotBlank(s3)){
            //1.根据逗号分隔
            String[] split = s3.split(",");
            if(split.length>0){
                for (int i = split.length - 1; i >= 0; i--) {
                    String trim = split[i].trim();
                    if(StringUtils.isNotBlank(trim)){
                        String[] split1 = trim.split("=");
                        map.put(split1[0],split1[1]);
                    }
                }
            }
        }
        return map;
    }

}
